package com.lft07.status;

/**
 * Function: 		A {@code TestSleep} 模拟网络延时<br/>
 * Reason:   		可以放大问题的发生性。<br/>
 *
 * Date:            2021-01-27 14:20<br/>
 * <p>
 * Class Name:      TestSleep<br/>
 * Package Name:    com.lft07.status<br/>
 * @author Laifengting / E-mail:laifengting@foxmail.com
 * @version 1.0.0
 * @since JDK 8
 */
public class TestSleep implements Runnable {
	// 票数
	private int ticketNums = 10;
	
	@Override
	public void run() {
		while (ticketNums > 0) {
			// 模拟延时
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println(Thread.currentThread().getName() + " ---> 拿到了第 " + ticketNums-- + " 票。");
		}
	}
	
	public static void main(String[] args) {
		TestSleep multiThreadProblem = new TestSleep();
		new Thread(multiThreadProblem, "小明").start();
		new Thread(multiThreadProblem, "老师").start();
		new Thread(multiThreadProblem, "黄牛").start();
		
	}
}
